<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="currentDate">
        <el-date-picker clearable
          v-model="queryParams.currentDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="巷道名称" prop="tunnelName">
        <el-input
          v-model="queryParams.tunnelName"
          placeholder="请输入巷道名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dispatch:drivingDayReport:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dispatch:drivingDayReport:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dispatch:drivingDayReport:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dispatch:drivingDayReport:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="drivingDayReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="日期" align="center" prop="currentDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.currentDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巷道名称" align="center" prop="tunnelName" />
      <el-table-column label="队组名称" align="center" prop="teamName" />
      <el-table-column label="计划进尺" align="center" prop="drivingPlanLength" />
      <el-table-column label="当日进尺" align="center" prop="drivingLength" />
      <el-table-column label="掘进岩性" align="center" prop="tunnelingLithology" />
      <el-table-column label="掘进方式" align="center" prop="tunnelingMethod" />
      <el-table-column label="当日管理情况" align="center" prop="administrativeSituation" />
      <el-table-column label="下井人数" align="center" prop="numberOfPeople" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dispatch:drivingDayReport:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dispatch:drivingDayReport:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改掘进日报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期" prop="currentDate">
          <el-date-picker clearable
            v-model="form.currentDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="巷道名称" prop="tunnelId">
          <el-select v-model="form.tunnelId" placeholder="请选择巷道" clearable>
            <el-option v-for="item in tunnelOptions" :key="item.tunnelId" :label="item.tunnelName" :value="item.tunnelId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="掘进队组" prop="teamId">
          <el-select v-model="form.teamId" placeholder="请选择掘进队组" clearable>
            <el-option v-for="item in teamOptions" :key="item.drivingTeamId" :label="item.teamName" :value="item.drivingTeamId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="计划进尺" prop="drivingPlanLength">
          <el-input v-model="form.drivingPlanLength" placeholder="请输入计划进尺" />
        </el-form-item>
        <el-form-item label="当日进尺" prop="drivingLength">
          <el-input v-model="form.drivingLength" placeholder="请输入当日进尺" />
        </el-form-item>
        <el-form-item label="掘进岩性" prop="tunnelingLithology">
          <el-select v-model="form.tunnelingLithology" placeholder="请选择岩性" clearable>
            <el-option label="全煤" value="全煤"></el-option>
            <el-option label="全岩" value="全岩"></el-option>
            <el-option label="半煤" value="半煤"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="掘进方式" prop="tunnelingMethod">
          <el-select v-model="form.tunnelingMethod" placeholder="请选择掘进方式" clearable>
            <el-option label="综掘" value="综掘"></el-option>
            <el-option label="炮掘" value="炮掘"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="当日管理情况" prop="administrativeSituation">
          <el-input v-model="form.administrativeSituation" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="下井人数" prop="numberOfPeople">
          <el-input v-model="form.numberOfPeople" placeholder="请输入下井人数" />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDrivingDayReport, getDrivingDayReport, delDrivingDayReport, addDrivingDayReport, updateDrivingDayReport } from "@/api/dispatch/drivingDayReport";
import { listTunnelInfo } from "@/api/dispatch/tunnelInfo";
import { listDrivingTeam } from "@/api/dispatch/drivingTeam";


export default {
  name: "DrivingDayReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //巷道选项
      tunnelOptions:[],
      //队组选项
      teamOptions:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 掘进日报表格数据
      drivingDayReportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        currentDate: null,
        tunnelName: null,
        teamName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    //获取巷道选项
    let query = {pageNum:1,pageSize: 1000}
    listTunnelInfo(query).then(response => {
      this.tunnelOptions = response.rows;
    });

    //获取开掘队选项
    listDrivingTeam(query).then(response => {
      this.teamOptions = response.rows;
    });
  },
  methods: {
    /** 查询掘进日报列表 */
    getList() {
      this.loading = true;
      listDrivingDayReport(this.queryParams).then(response => {
        this.drivingDayReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        reportId: null,
        mineId: null,
        currentDate: null,
        tunnelId: null,
        tunnelName: null,
        teamId: null,
        teamName: null,
        drivingPlanLength: null,
        drivingLength: null,
        tunnelingLithology: null,
        tunnelingMethod: null,
        administrativeSituation: null,
        numberOfPeople: null,
        sort: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.reportId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加掘进日报";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const reportId = row.reportId || this.ids
      getDrivingDayReport(reportId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改掘进日报";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.reportId != null) {
            updateDrivingDayReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDrivingDayReport(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const reportIds = row.reportId || this.ids;
      this.$modal.confirm('是否确认删除掘进日报编号为"' + reportIds + '"的数据项？').then(function() {
        return delDrivingDayReport(reportIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dispatch/drivingDayReport/export', {
        ...this.queryParams
      }, `drivingDayReport_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
